.class public Lcom/facebook/orca/protocol/SimulatedBatchRunner;
.super Lcom/facebook/orca/protocol/BatchRunner;
.source "SimulatedBatchRunner.java"


# static fields
.field private static final a:Ljava/util/regex/Pattern;


# instance fields
.field private b:Lcom/facebook/orca/protocol/SingleMethodRunner;

.field private c:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation
.end field


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 25
    const-string v0, "\\{result=([^}:]*):([^}]*)\\}"

    invoke-static {v0}, Ljava/util/regex/Pattern;->compile(Ljava/lang/String;)Ljava/util/regex/Pattern;

    move-result-object v0

    sput-object v0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->a:Ljava/util/regex/Pattern;

    return-void
.end method

.method public constructor <init>(Lcom/facebook/orca/protocol/SingleMethodRunner;)V
    .locals 1
    .parameter
    .annotation runtime Lcom/google/inject/Inject;
    .end annotation

    .prologue
    .line 32
    invoke-direct {p0}, Lcom/facebook/orca/protocol/BatchRunner;-><init>()V

    .line 28
    invoke-static {}, Lcom/google/common/collect/Maps;->a()Ljava/util/HashMap;

    move-result-object v0

    iput-object v0, p0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->c:Ljava/util/Map;

    .line 33
    iput-object p1, p0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->b:Lcom/facebook/orca/protocol/SingleMethodRunner;

    .line 34
    return-void
.end method

.method private a(Lcom/facebook/orca/protocol/ApiRequest;)Lcom/facebook/orca/protocol/ApiRequest;
    .locals 6
    .parameter

    .prologue
    .line 60
    invoke-direct {p0, p1}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->b(Lcom/facebook/orca/protocol/ApiRequest;)Z

    move-result v0

    if-nez v0, :cond_0

    move-object v0, p1

    .line 68
    :goto_0
    return-object v0

    .line 63
    :cond_0
    invoke-virtual {p1}, Lcom/facebook/orca/protocol/ApiRequest;->c()Ljava/lang/String;

    move-result-object v0

    invoke-direct {p0, v0}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->c(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v3

    .line 64
    invoke-static {}, Lcom/google/common/collect/Lists;->a()Ljava/util/ArrayList;

    move-result-object v4

    .line 65
    invoke-virtual {p1}, Lcom/facebook/orca/protocol/ApiRequest;->d()Lcom/google/common/collect/ImmutableList;

    move-result-object v0

    invoke-virtual {v0}, Lcom/google/common/collect/ImmutableList;->iterator()Ljava/util/Iterator;

    move-result-object v1

    :goto_1
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_1

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lorg/apache/http/NameValuePair;

    .line 66
    new-instance v2, Lorg/apache/http/message/BasicNameValuePair;

    invoke-interface {v0}, Lorg/apache/http/NameValuePair;->getName()Ljava/lang/String;

    move-result-object v5

    invoke-interface {v0}, Lorg/apache/http/NameValuePair;->getValue()Ljava/lang/String;

    move-result-object v0

    invoke-direct {p0, v0}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->c(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    invoke-direct {v2, v5, v0}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v4, v2}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    goto :goto_1

    .line 68
    :cond_1
    new-instance v0, Lcom/facebook/orca/protocol/ApiRequest;

    invoke-virtual {p1}, Lcom/facebook/orca/protocol/ApiRequest;->a()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {p1}, Lcom/facebook/orca/protocol/ApiRequest;->b()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {p1}, Lcom/facebook/orca/protocol/ApiRequest;->e()Lorg/apache/http/entity/mime/FormBodyPart;

    move-result-object v5

    invoke-direct/range {v0 .. v5}, Lcom/facebook/orca/protocol/ApiRequest;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lorg/apache/http/entity/mime/FormBodyPart;)V

    goto :goto_0
.end method

.method private b(Lcom/facebook/orca/protocol/ApiRequest;)Z
    .locals 4
    .parameter

    .prologue
    const/4 v3, 0x1

    .line 77
    invoke-virtual {p1}, Lcom/facebook/orca/protocol/ApiRequest;->c()Ljava/lang/String;

    move-result-object v0

    invoke-direct {p0, v0}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->d(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    move v0, v3

    .line 87
    :goto_0
    return v0

    .line 80
    :cond_0
    invoke-virtual {p1}, Lcom/facebook/orca/protocol/ApiRequest;->d()Lcom/google/common/collect/ImmutableList;

    move-result-object v0

    invoke-virtual {v0}, Lcom/google/common/collect/ImmutableList;->iterator()Ljava/util/Iterator;

    move-result-object v0

    :cond_1
    invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z

    move-result v1

    if-eqz v1, :cond_2

    invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object p0

    check-cast p0, Lorg/apache/http/NameValuePair;

    .line 81
    invoke-interface {p0}, Lorg/apache/http/NameValuePair;->getValue()Ljava/lang/String;

    move-result-object v1

    .line 82
    sget-object v2, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->a:Ljava/util/regex/Pattern;

    invoke-virtual {v2, v1}, Ljava/util/regex/Pattern;->matcher(Ljava/lang/CharSequence;)Ljava/util/regex/Matcher;

    move-result-object v1

    .line 83
    invoke-virtual {v1}, Ljava/util/regex/Matcher;->find()Z

    move-result v1

    if-eqz v1, :cond_1

    move v0, v3

    .line 84
    goto :goto_0

    .line 87
    :cond_2
    const/4 v0, 0x0

    goto :goto_0
.end method

.method private c(Ljava/lang/String;)Ljava/lang/String;
    .locals 5
    .parameter

    .prologue
    .line 91
    invoke-direct {p0, p1}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->d(Ljava/lang/String;)Z

    move-result v0

    if-nez v0, :cond_0

    move-object v0, p1

    .line 108
    :goto_0
    return-object v0

    .line 95
    :cond_0
    sget-object v0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->a:Ljava/util/regex/Pattern;

    invoke-virtual {v0, p1}, Ljava/util/regex/Pattern;->matcher(Ljava/lang/CharSequence;)Ljava/util/regex/Matcher;

    move-result-object v1

    .line 96
    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    .line 97
    :goto_1
    invoke-virtual {v1}, Ljava/util/regex/Matcher;->find()Z

    move-result v0

    if-eqz v0, :cond_2

    .line 98
    const/4 v0, 0x1

    invoke-virtual {v1, v0}, Ljava/util/regex/Matcher;->group(I)Ljava/lang/String;

    move-result-object v3

    .line 99
    const/4 v0, 0x2

    invoke-virtual {v1, v0}, Ljava/util/regex/Matcher;->group(I)Ljava/lang/String;

    move-result-object v4

    .line 100
    iget-object v0, p0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->c:Ljava/util/Map;

    invoke-interface {v0, v3}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    .line 101
    if-nez v0, :cond_1

    .line 102
    new-instance v0, Ljava/lang/Exception;

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "No json result named "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/Exception;-><init>(Ljava/lang/String;)V

    throw v0

    .line 104
    :cond_1
    invoke-static {v0, v4}, Lcom/jayway/jsonpath/JsonPath;->a(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    .line 105
    invoke-virtual {v1, v2, v0}, Ljava/util/regex/Matcher;->appendReplacement(Ljava/lang/StringBuffer;Ljava/lang/String;)Ljava/util/regex/Matcher;

    goto :goto_1

    .line 107
    :cond_2
    invoke-virtual {v1, v2}, Ljava/util/regex/Matcher;->appendTail(Ljava/lang/StringBuffer;)Ljava/lang/StringBuffer;

    .line 108
    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v0

    goto :goto_0
.end method

.method private d(Ljava/lang/String;)Z
    .locals 1
    .parameter

    .prologue
    .line 112
    sget-object v0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->a:Ljava/util/regex/Pattern;

    invoke-virtual {v0, p1}, Ljava/util/regex/Pattern;->matcher(Ljava/lang/CharSequence;)Ljava/util/regex/Matcher;

    move-result-object v0

    .line 113
    invoke-virtual {v0}, Ljava/util/regex/Matcher;->find()Z

    move-result v0

    return v0
.end method


# virtual methods
.method public b(Ljava/lang/String;)V
    .locals 9
    .parameter

    .prologue
    .line 37
    invoke-virtual {p0}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->a()Ljava/util/List;

    move-result-object v0

    .line 38
    invoke-interface {v0}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_1

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/facebook/orca/protocol/BatchOperation;

    .line 39
    invoke-virtual {v0}, Lcom/facebook/orca/protocol/BatchOperation;->c()Ljava/lang/String;

    move-result-object v2

    .line 40
    invoke-virtual {v0}, Lcom/facebook/orca/protocol/BatchOperation;->a()Lcom/facebook/orca/protocol/ApiMethod;

    move-result-object v3

    .line 42
    invoke-virtual {v0}, Lcom/facebook/orca/protocol/BatchOperation;->b()Ljava/lang/Object;

    move-result-object v4

    .line 44
    invoke-interface {v3, v4}, Lcom/facebook/orca/protocol/ApiMethod;->a(Ljava/lang/Object;)Lcom/facebook/orca/protocol/ApiRequest;

    move-result-object v4

    invoke-direct {p0, v4}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->a(Lcom/facebook/orca/protocol/ApiRequest;)Lcom/facebook/orca/protocol/ApiRequest;

    move-result-object v4

    .line 45
    iget-object v5, p0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->b:Lcom/facebook/orca/protocol/SingleMethodRunner;

    invoke-virtual {v5, v4}, Lcom/facebook/orca/protocol/SingleMethodRunner;->a(Lcom/facebook/orca/protocol/ApiRequest;)Lcom/facebook/orca/protocol/SingleMethodRunner$InternalResult;

    move-result-object v4

    .line 46
    new-instance v5, Lcom/facebook/orca/protocol/ApiResponse;

    iget-object v6, v4, Lcom/facebook/orca/protocol/SingleMethodRunner$InternalResult;->a:Lorg/apache/http/HttpResponse;

    invoke-interface {v6}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v6

    invoke-interface {v6}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v6

    iget-object v7, v4, Lcom/facebook/orca/protocol/SingleMethodRunner$InternalResult;->a:Lorg/apache/http/HttpResponse;

    invoke-interface {v7}, Lorg/apache/http/HttpResponse;->getAllHeaders()[Lorg/apache/http/Header;

    move-result-object v7

    invoke-static {v7}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;

    move-result-object v7

    iget-object v8, v4, Lcom/facebook/orca/protocol/SingleMethodRunner$InternalResult;->b:Ljava/lang/String;

    invoke-direct {v5, v6, v7, v8}, Lcom/facebook/orca/protocol/ApiResponse;-><init>(ILjava/util/List;Ljava/lang/String;)V

    .line 51
    if-eqz v2, :cond_0

    .line 52
    iget-object v6, p0, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->c:Ljava/util/Map;

    iget-object v4, v4, Lcom/facebook/orca/protocol/SingleMethodRunner$InternalResult;->b:Ljava/lang/String;

    invoke-interface {v6, v2, v4}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 54
    :cond_0
    invoke-virtual {v0}, Lcom/facebook/orca/protocol/BatchOperation;->b()Ljava/lang/Object;

    move-result-object v2

    invoke-interface {v3, v2, v5}, Lcom/facebook/orca/protocol/ApiMethod;->a(Ljava/lang/Object;Lcom/facebook/orca/protocol/ApiResponse;)Ljava/lang/Object;

    move-result-object v2

    .line 55
    invoke-virtual {v0}, Lcom/facebook/orca/protocol/BatchOperation;->c()Ljava/lang/String;

    move-result-object v0

    invoke-virtual {p0, v0, v2}, Lcom/facebook/orca/protocol/SimulatedBatchRunner;->a(Ljava/lang/String;Ljava/lang/Object;)V

    goto :goto_0

    .line 57
    :cond_1
    return-void
.end method
